/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import common.Application;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.LinkedList;
import templates.PropertyTemplate;
import templates.Template;
import utils.GenericPair;
import utils.ResultSetWrap;

/**
 *
 * @author Alejandro
 */
public class ResultSetRow {

    private Collection<GenericPair<Short, String>> values = new LinkedList<GenericPair<Short, String>>();
    private static Template template;

    public static void bind(short uid) {
        template = Application.getInstance().getTemplate(uid);
    }

    public ResultSetRow(ResultSetWrap rs) {
        for (PropertyTemplate pt : template.getPropertyTemplateCollection()) {
            String s = "";
            if (rs.getValue(pt.getName()) != null) {
                s = rs.getValue(pt.getName());
            } else {
                if (pt.isNullEnabled()) {
                    s = pt.getNullValue();
                }
            }
            values.add(new GenericPair(pt.getUid(), s));
        }
    }

    public String getValue(short uid) {
        String value = null;
        for (GenericPair<Short, String> gp : values) {
            if (gp.getFirst() == uid) {
                value = gp.getSecond();
            }
        }
        return value;
    }
}
